<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('光刻板出入库信息列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="post-form">
					<div class="select-list">
						<ul>
							<li>
								光刻板名称：<input type="text" name="lightPlateNo"/>
							</li>
							<li>
								状态：
								<select name="lightPlateStatus" th:with="type=${@dict.getType('light_plate_status')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								是否异常：
								<select name="isAbnormal" th:with="type=${@dict.getType('is_abnormal')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-primary single disabled" onclick="warehousing();" shiro:hasPermission="ph:plateinout:warehousing">
					<i class="fa fa-sign-in"></i> 入库
				</a>
				<a class="btn btn-warning single disabled" onclick="outbound();" shiro:hasPermission="ph:plateinout:outbound">
					<i class="fa fa-sign-out"></i> 出库
				</a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var plateInFlag = [[${@permission.hasPermi('ph:plateinout:warehousing')}]];
		var plateOutFlag = [[${@permission.hasPermi('ph:plateinout:outbound')}]];

		var lightPlateStatus = [[${@dict.getType('light_plate_status')}]];
		var useStatus = [[${@dict.getType('use_status')}]];
		var isAbnormal = [[${@dict.getType('is_abnormal')}]];

		var splictPage = [10, 20, 30, 50];

		var prefixPlateInfo = ctx + "ph/plateinfo";
		var prefix = ctx + "ph/plateinout";

		var options = {
			url: prefixPlateInfo + "/list",
			sortName: "create_time desc,id",
			sortOrder: "desc",
			modalName: "光刻板",
			pageList: splictPage,
			columns: [
				{
					checkbox: true
				},
				{
					field: 'lightPlateNo',
					title: '光刻板名称',
					sortable: true
				},
				{
					field: 'lightPlatePlace',
					title: '位置',
					sortable: true
				},
				{
					field: 'lightPlateStatus',
					title: '状态',
					sortable: true,
					align: 'center',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(lightPlateStatus, value);
					}
				},
				{
					field: 'isAbnormal',
					title: '是否异常',
					sortable: true,
					align: 'center',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(isAbnormal, value);
					}
				},
				{
					field: 'remark',
					title: '备注',
					sortable: true
				},
				{
					field: 'useStatus',
					title: '启用标识',
					align: 'center',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(useStatus, value);
					}
				},
				{
					field: 'useTime',
					title: '启用日期',
					sortable: true
				},
				{
					field: 'stopTime',
					title: '停用日期',
					sortable: true
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-primary btn-xs ' + plateInFlag + '" href="javascript:void(0)" onclick="warehousing(\''
								+ row.lightPlateNo + '\')"><i class="fa fa-sign-in"></i>入库</a>&nbsp;&nbsp;&nbsp;&nbsp;');

						actions.push('<a class="btn btn-warning btn-xs ' + plateOutFlag + '" href="javascript:void(0)" onclick="outbound(\''
								+ row.lightPlateNo + '\')"><i class="fa fa-sign-out"></i>出库</a> ');
						return actions.join('');
					}
				}
			]
		};

		$(function() {
		    $.table.init(options);
		});

		/**
		 * 出库
		 */
		function outbound(plateNo) {
			let url = prefix + "/outbound";
			sendPlateInOutRequest(plateNo, url, "出库");
		}

		/**
		 * 入库
		 */
		function warehousing(plateNo) {
			let url = prefix + "/warehousing";
			sendPlateInOutRequest(plateNo, url, "入库");
		}

		function sendPlateInOutRequest(plateNo, url, msg) {
			let lightPlateNo = plateNo;
			if ($.common.isEmpty(lightPlateNo)) {
				var row = $.table.selectColumns("lightPlateNo");
				if ($.common.isEmpty(row)) {
					$.modal.alertWarning("请至少选择一条记录");
					return;
				}
				lightPlateNo = row;
			}
			$.ajax({
				url: url,
				data: {
					"lightPlateNo": lightPlateNo
				},
				type: "post",
				dataType: "json",
				async : false,
				beforeSend : function () {
					$.modal.loading("正在处理中......");
				},
				error : function(request) {
					$.modal.alertError("系统错误！");
				},
				success: function (result) {
					if (result.code === web_status.SUCCESS) {
						$.modal.alertSuccess(msg + "成功！");
						$.table.refresh();
					} else if (result.code === web_status.WARNING) {
						$.modal.alertWarning(result.msg);
					} else if (result.code === web_status.FAIL) {
						$.modal.alertWarning("该操作报错，错误信息为：" + result.msg);
					} else {
						$.modal.alertError(result.msg);
					}
				},
				complete: function () {
					$.modal.closeLoading();
				}
			});
		}

	</script>
</body>
</html>